/**************************************************************************
*   Copyleft 2009 by        											  *
*	Iwanicki Krzysztof													  *
*   <www.gamma.mini.pw.edu.pl/~iwanickik>		                          *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
***************************************************************************/
#ifndef __VSETTINGS_H__
#define __VSETTINGS_H__

#include "../../Utils/vUtils.h"
#include "../../Macros/vMemoryMacros.h"

namespace Vendetta {
	typedef vHashMap<vString, vString>			vStringMap;
	typedef vHashMap<vString, vStringMap>		vSectionMap;

	/*! \class vSettings
	 *  \brief A vSettings class contains information structured into sections.
	 *  
	 *  
	 *  Informations are structured in section like below:
	 *
	 *  \verbatim
	 *  ;comment
	 *  @new comment
	 *
	 *  key1 : value3
	 *  key1	value3
	 *
	 *  #some comment
	 *  [Section name1]
	 *  key1	value1
	 *  key2:value2
	 *  key3 = value3
	 *  
	 *  [Section name2]
	 *  key1=value1
	 *  key2: value2
	 *  key3 : value3
	 *
	 *  etc.
	 *	\endverbatim
	 *
	 *  It can be used to store config files, some usefull informations that user 
	 *  can change by hand. To comment some part of file use # (hash) or ; (semicolon) or @ (at) character before text.
	 *  Each key/val entry can be delimeter by : (colon) or \t (tab) or = (equal) character.
	 */
	class vSettings {
	public:
		/*! \brief Default constructor.
		 *
		 */	
		vSettings();
	
		/*! \brief Destructor.
		 *
		 */	
		virtual ~vSettings();

		/*! \brief Loads settings from given file name.
		 *
		 *			 
		 *  \param		fileName		File name containing settings to load.
		 *	\exception	vException		Thrown when file format is not good or can't read from file or file does not exists.
		 *	\sa			vString.
		 */	
		vVoid LoadFromFile(const vString& fileName);

		/*! \brief Returns setting value for given setting name.
		 *
		 *	
		 *  \param		name			Setting name.
		 *  \param		section			Section name.
		 *	\return						Setting value as string.
		 *	\exception	vException		Thrown when setting or section with given name does not exists.
		 *	\sa			vString.
		 */
		const vString& Setting(const vString& name, const vString& section = "Default");

		/*! \brief Returns setting kay/value pairs for given section name.
		 *
		 *	
		 *  \param		section			Section name.
		 *	\return						Settings for give section.
		 *	\exception	vException		Thrown when section with given name does not exists.
		 *	\sa			vString.
		 */
		const vHashMap<vString, vString>& Settings(const vString& section = "Default");


	protected:
		/*! \brief Transfers string entry into setting entry.
		 *
		 *	If file contain entries key/value without section assigned,
		 *  "Default" section is created and entries are attached to it.
		 *  Only entries before any defined section are assigned to it.
		 *			 
		 *  \param		strLine			Line for transformation.
		 *  \param		currentSection	Current section, if not set Default is use.
		 *	\return						Current section name.
		 *	\exception	vException		Thrown when file format is not good.
		 *	\sa			vString.
		 */	
		const vString readLine(const vString& strLine, const vString& currentSection);

	protected:
		vSectionMap mSections;
	
	};
}

#endif // __VSETTINGS_H__